//
//  LXStatusCell.swift
//  weibo
//
//  Created by 罗心 on 16/6/27.
//  Copyright © 2016年 罗心. All rights reserved.
//

import UIKit
import SnapKit

class LXStatusCell: UITableViewCell {
    
    var toolBarTopConstraint: Constraint?
    
    
    var ststus:LXStatus?{
        didSet{
            statusOringinalView.status = ststus
            
            toolBarTopConstraint?.uninstall()
            
            if ststus?.retweeted_status == nil {
                statusRetweetView.hidden = true
                statusToolbar.snp_makeConstraints(closure: { (make) in
                    toolBarTopConstraint = make.top.equalTo(statusOringinalView.snp_bottom).constraint
                })
            } else {
                statusRetweetView.status = ststus
                statusRetweetView.hidden = false
                statusToolbar.snp_makeConstraints(closure: { (make) in
                    toolBarTopConstraint = make.top.equalTo(statusRetweetView.snp_bottom).constraint
                })
            }
            statusToolbar.status = ststus
        
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI(){
        
        //添加控件
        addSubview(statusOringinalView)
        addSubview(statusRetweetView)
        addSubview(statusToolbar)
        
        //设置约束
        statusOringinalView.snp_makeConstraints { (make) in
            make.top.leading.trailing.equalTo(contentView)
//            make.height.equalTo(50)
        }
        statusRetweetView.snp_makeConstraints { (make) in
            make.top.equalTo(statusOringinalView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
//            make.height.equalTo(50)
        }
        statusToolbar.snp_makeConstraints { (make) in
            toolBarTopConstraint = make.top.equalTo(statusRetweetView.snp_bottom).constraint
            make.height.equalTo(35)
            make.leading.trailing.equalTo(contentView)
        }
        
        contentView.snp_makeConstraints { (make) in
            make.bottom.equalTo(statusToolbar.snp_bottom)
            make.top.leading.trailing.equalTo(self)
        }
    }
    
    //LXStatusOringinalView
    private lazy var statusOringinalView: LXStatusOringinalView = LXStatusOringinalView()
    private lazy var statusRetweetView: LXStatusRetweetView = LXStatusRetweetView()
    private lazy var statusToolbar: LXStatusToolbar = LXStatusToolbar()

}
